﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KNXObjects.Enum;

namespace KNXObjects
{
    public class SwitchingObject : GenericObjectBase<bool>
    {
        #region ObjectBase Implementations

        public override string ToString()
        {
            return Value ? "On" : "Off";
        }
        public override string DataPointEISName
        {
            get { return "EIS1"; }
        }
        public override string DataPointID
        {
            get { return "1.001"; }
        }

        public override void SetValue(string value)
        {
            value = value.ToLower();
            if (value == "1" || value == "on" || value == "true")
                Value = true;
            else if (value == "0" || value == "off" || value == "false")
                Value = false;
            else
            {
                throw new ApplicationException("Invalid switching value");
            }
            
        }        

        #endregion

        #region ctor

        public SwitchingObject(string id, string address, string name, string flags)
            : base(id, address, name, flags)
        {
        }

        public SwitchingObject(bool value)
        {
            Value = value;
        }

        public SwitchingObject(string value)
        {
            SetValue(value);
        }

        #endregion
    }
}
